package cn.wit.backen.controller;

import cn.wit.backen.condition.LoginCondition;
import cn.wit.backen.service.LoginService;
import cn.wit.utils.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "登录相关")
@CrossOrigin
public class LoginController {
    @Autowired
    private LoginService loginService;


    @PostMapping("login")
    @ApiOperation("登陆")
    public Result logqueryContestin(@RequestBody LoginCondition condition) {
        return Result.ok(loginService.login(condition));

    }

    @PostMapping("logout")
    @ApiOperation("登出")
    public Result logout(String token) {
        loginService.logout(token);
        return Result.ok();
    }

    @PostMapping("/updatePwd")
    @ApiOperation("修改密码")
    public Result updatePwd(String username , String oldPassword, String newPassword) {
        return loginService.updatePwd(username, oldPassword, newPassword);
    }
}
